package com.kitty.game.task;

import com.kitty.game.config.Instruction;
import com.kitty.game.config.TaskSet;
import com.kitty.game.activity.service.task.TaskActivityHandler;
import com.kitty.game.task.model.product.TaskType;
import com.kitty.game.task.service.taskHandler.TaskHandler;
import com.kitty.game.utils.ClassScanner;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 任务产品数据
 */
public class TaskDataPool {

    /**指引类型对应的指引数据*/
    public static Map<Byte,Map<Integer, Set<Instruction>>> typeToInstruction;

    /**任务集合，key:任务id, value:[key: 门派  value: 任务配置]*/
    public static Map<Integer, Map<Byte, TaskSet>> taskMapBySchool;

    /**对话id对应的任务, key:任务id, value:任务id*/
    public static Map<Integer, Integer> talkToTaskMap;

    /**key: 任务类型， value: 任务id(每组任务只保存第1个任务)*/
    public static Map<TaskType, List<Integer>> taskListByType;

    /**助人为乐任务中需要帮助的人对应任务 key: 需要帮助的人， value: 任务id*/
    public static Map<String , Integer> helpTaskByName;

    public static Map<TaskType, Class> type2Handler;

    /**第一个主线的任务，新建角色时需要接取*/
    public static final int FIRST_MAIN_TASKID = 1;

    /**师门任务引导作用的任务ID*/
    public static final int SCHOOL_GUIDE_TASKID = 2000;

    /**主线指引领取师门任务的任务ID，需要完成这个任务后才显示领取按钮*/
    public static final int MAIN_SCHOOL_TASKID = 39;

    /**放弃师门任务后再接时的等待时间(毫秒数)*/
    public static final int DELAY_TIME_AFTER_GIVEUP_SCHOOL = 5 * 60 * 1000;

    /**放弃助人为乐任务后再接时的等待时间(毫秒数)*/
    public static final int DELAY_TIME_AFTER_GIVEUP_HELP_PEOPLE = 5 * 60 * 1000;

    /**放弃宠物飞升任务后再接时的等待时间(毫秒数)*/
    public static final int DELAY_TIME_AFTER_GIVEUP_HELP_PET_FLY = 5 * 60 * 1000;

    /**除暴对应的任务ID*/
    public static final int CHU_BAO_TASKID = 71;

    /**主线任务中学习的任务id，进行特殊处理*/
    public static int studySkillTaskId;

    /**使用天神护佑后自动接取的任务ID*/
    public static final int GOD_PROTECT_TASKID = 666;

    /**使用变身卡接取的任务ID*/
    public static final int CHANGE_CARD_TASKID = 1000;

    /**使用九曲玲珑笔的任务ID*/
    public static final int SHAPE_PEN_TASKID = 1001;

    /**主线拜师获得称号的任务ID*/
    public static final int MAIN_SCHOOL_TITLE_TASKID = 22;

    /**杀气腾腾任务ID*/
    public static final int KILL_TASKID = 670;
    /**孽债血海任务ID*/
    public static final int RED_TASKID = 671;
    /**坐牢任务ID*/
    public static final int PRISON_TASKID = 672;

    /**积分显示ID*/
    public static final int RECHARGE_SCORE_TASKID = 999;

    /**阵营引导任务ID*/
    public static final int CAMP_GUIDE = 2205;

    /**阵营选择任务ID*/
    public static final int CAMP_SELECTION = 2206;

    /**成仙之路引导作用的任务ID*/
    public static final int CHENG_XIAN_ZHI_LU = 2209;

    /**仙魔难任务ID*/
    public static final int FLY_XIAN_MO = 2211;

    /**初始化任务类型对应的处理类*/
    public static void initType2Handler() {
        Set<Class<?>> handlers = new HashSet<>();

        String scanPath = "com.kitty.game";
        Set<Class<?>> handler = ClassScanner.listAllSubclasses(scanPath, TaskHandler.class);
        if (handler != null) {
            handlers.addAll(handler);
        }
        handler = ClassScanner.listAllSubclasses(scanPath, TaskActivityHandler.class);
        if (handler != null) {
            handlers.addAll(handler);
        }

        Map<TaskType, Class> type2Handler = new HashMap<>();
        for (Class<?> clazz : handlers) {
            try {
                Object instance = clazz.newInstance();
                if (instance instanceof TaskHandler) {
                    type2Handler.put(((TaskHandler)instance).getTaskType(), clazz);
                } else if (instance instanceof TaskActivityHandler) {
                    type2Handler.put(((TaskActivityHandler)instance).getTaskType(), clazz);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        TaskDataPool.type2Handler = type2Handler;
    }
}
